package question1;

import java.util.AbstractSet;
import java.util.Iterator;
import java.util.Vector;

public class Ensemble<T> extends AbstractSet<T>
{
	private Vector<T> table;

	public Ensemble() { table = new Vector<T>(); }

	@Override public int size() { return table.size(); }

	@Override public Iterator<T> iterator() 
	{ 
		return table.iterator(); 
	}

	@Override public boolean add(T t)
	{  
		if(contains(t)){	    
			return false;
		}
		return table.add(t);
	} // add()

	public Ensemble<T> union( Ensemble<? extends T> e)
	{ 
		Ensemble<T> t = new Ensemble<T>();
		t.addAll(e); 
		t.addAll(this);
		return t;
	} // union()

	public Ensemble<T> inter( Ensemble<? extends T> e)
	{
		Ensemble<T> t = new Ensemble<T>();
		t.addAll(this);
		t.retainAll(e);
		return t;
	} // inter()

	public Ensemble<T> diff( Ensemble<? extends T> e)
	{
		Ensemble<T> t = new Ensemble<T>();
		t.addAll(this);
		t.removeAll(e);
		return t;
	} // diff()

	Ensemble<T> diffSym( Ensemble<? extends T> e)
	{
		Ensemble<T> t = new Ensemble<T>();
		t = this.union(e);
		t.removeAll(this.inter(e));
		return t;
	} // diffSym()
} // Ensemble
